from django.db import models


class Admin(models.Model):
    admin_id = models.CharField(max_length=6, primary_key=True)
    admin_pass = models.CharField(max_length=12)
    register_time = models.DateTimeField(auto_now_add=True)
    last_operation_time = models.DateTimeField(auto_now=True)
    responsible_scenic_id = models.CharField(max_length=60, blank=True, null=True)
    submitted_tickets = models.IntegerField(default=0)


class Submitter(models.Model):
    submitter_id = models.CharField(max_length=6, primary_key=True)
    submitter_pass = models.CharField(max_length=12)
    register_time = models.DateTimeField(auto_now_add=True)
    last_operation_time = models.DateTimeField(auto_now=True)
    submitted_tickets = models.IntegerField(default=0)


class DataChange(models.Model):
    change_id = models.AutoField(primary_key=True)
    qa = models.ForeignKey('QaPair', on_delete=models.CASCADE, db_column='qa_id', blank=True, null=True)
    current_status = models.CharField(max_length=20, default='on')
    modification_type = models.CharField(max_length=20, blank=True, null=True)
    original_question = models.TextField(blank=True, null=True)  # 修改为 TextField
    original_answer = models.TextField(blank=True, null=True)  # 修改为 TextField
    updated_question = models.TextField(blank=True, null=True)  # 修改为 TextField
    updated_answer = models.TextField(blank=True, null=True)  # 修改为 TextField
    change_time = models.DateTimeField(auto_now_add=True)
    modified_by = models.CharField(max_length=6, blank=True, null=True)
    ticket = models.ForeignKey('DataTicket', on_delete=models.CASCADE, db_column='ticket_id', blank=True, null=True)


class DataTicket(models.Model):
    ticket_id = models.AutoField(primary_key=True)
    ticket_type = models.CharField(max_length=3)
    question = models.TextField()  # 修改为 TextField
    answer = models.TextField()  # 修改为 TextField
    submitter = models.ForeignKey(Submitter, on_delete=models.CASCADE, db_column='submitter_id', blank=True, null=True)
    submit_time = models.DateTimeField(auto_now_add=True)
    submit_count = models.IntegerField(default=0)
    assigned_admin = models.ForeignKey(Admin, on_delete=models.CASCADE, db_column='assigned_admin', blank=True,
                                       null=True)
    status = models.CharField(max_length=20, default='待处理')


class QaPair(models.Model):
    qa_id = models.AutoField(primary_key=True)
    jq = models.ForeignKey('ScenicSpot', on_delete=models.CASCADE, db_column='jq_id', blank=True, null=True)
    question = models.CharField(max_length=100)
    answer = models.TextField(blank=True, null=True)  # 修改为 TextField
    last_operation_time = models.DateTimeField(auto_now=True)


class ScenicSpot(models.Model):
    jq_id = models.CharField(max_length=60, primary_key=True)
    jq_name = models.CharField(max_length=50)
    jq_city = models.CharField(max_length=20)
    jq_address = models.TextField(null=True)  # 修改为 TextField
    jq_rating = models.CharField(max_length=50)
    jq_type = models.CharField(max_length=20)
    qa_count = models.IntegerField(default=0)
    responsible_admin = models.ForeignKey(Admin, on_delete=models.CASCADE, db_column='responsible_admin', blank=True, null=True)

